package cn.ichiva.game.poker.ddz.cardType.impl;

import cn.ichiva.game.poker.ddz.Card;
import cn.ichiva.game.poker.ddz.ICardType;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description 四带一
 * @auther Chiva 874460517@qq.com
 * @create 2020-01-13 16:04
 */
public class Type4And4Card extends CardType {

    int num=6;

    public Type4And4Card(Card[] cards) {
        super(cards);
    }


    @Override
    public boolean cardTypeCheck() {
        if(num == cards.length){
            Map<Integer,Integer> map = new HashMap<>();
            for (Card card : cards) {
                int index = card.getIndex();
                Integer integer = map.get(index);
                if(null == integer){
                    integer = 0;
                }

                map.put(index,integer++);
            }

            Collection<Integer> values = map.values();
            return Collections.max(values) == 4 && Collections.min(values) == 2 ;
        }

        return false;
    }
}
